import {
	myRequest
} from './api.js'

// 获取高度tabBar剩余的高度
export const getHeight = () => {
	//获取手机系统信息 -- 状态栏高度
	let {
		statusBarHeight,
		windowHeight
	} = uni.getSystemInfoSync()
	//去除
	//#ifndef H5 || MP-ALIPAY ||APP-PLUS
	//获取小程序胶囊的高度
	let {
		top,
		bottom,
		left
	} = uni.getMenuButtonBoundingClientRect()
	//高度 =（胶囊底部高低-状态栏高度）+（胶囊顶部高度-状态栏内的高度）
	let navBareight = (bottom - statusBarHeight) + (top - statusBarHeight)
	return {
		windowHeight,
		statusBarHeight,
		navBareight
	}
	//#endif
}

//获取openKey

export const getOpenKey = () => {
	// 获取openKey
	wx.login({
		success: function(res) {
			var code = res.code;
			if (code) {
				myRequest({
					url: `OpenID?code=${code}`,
					contentType: 'application/x-www-form-urlencoded',
				}).then(result => {
					if (result) {
						uni.setStorageSync('openkey', result)
					}
				})
			} else {
				console.log('获取用户登录态失败：' + res.errMsg);
			}
		}
	});
}